<? 
	include('base.php');
	User::protect();
	include_class('releases');
	include_class('band_members');
	
	$r = Release::get($_REQUEST['id']);
	if ($_GET['task'] == 'select' && !db::isError($r)) {
		$res = $r->selectBandMembers($_POST['member_id']);
		if (!db::isError($res)) { ?>
			<script type="text/javascript">self.close(); opener.location.reload();</script>
		<?
		}
	}

	$page_title = 'Release Band Members';
	$stylesheet = 'popup.css';
	include('layout/header_popup.php');
	
	
if (User::isAdmin()) { ?>
	
<?
	if (!db::isError($r)) {
		$selectedBMArray = $r->getReleaseBandMembers();
		if (!db::isError($selectedBMArray)) { 
			$bmIDArray = array();
			foreach($selectedBMArray as $bm) {
				$bmIDArray[] = $bm->getID();
			}
			unset($selectedBMArray);
			
			$bmArray = BandMemberList::get_band_members();
			if (!db::isError($selectedBbmArrayMArray)) { ?>
		
				<h1><?=$r->getTitle()?></h1>
				<div class="inset">
				<form id="add_alias" action="<?=$PHP_SELF?>?task=select&amp;id=<?=$_GET['id']?>" method="post">
				<table class="list" border="0" cellspacing="1" cellpadding="0">
				<? foreach($bmArray as $bm) { 
					$uo = $bm->getUserObject();
						?>
					<tr>
						<td><input type="checkbox" name="member_id[]" value="<?=$bm->getID()?>"<? if (in_array($bm->getID(), $bmIDArray)) { ?> checked<? } ?>></td>
						<td style="white-space: nowrap"><?=$uo->getFirstName()?> <?=$uo->getLastName()?></td>
						<td><?=$bm->getRole()?></td>
					</tr>
				
					<? } ?>	
				</table>
				<br/>
				<input type="submit" value="Select Band Members" name="submit" class="button">
				<input type="submit" value="Exit and Close Window" name="exit" onclick="javascript:top.close(); return false" class="button">
				</form>
				</div>
			<? } else { 
			
				$bmArray->outputDialog('Close Window','javascript:self.close()');			
		
			}
			
		} else {
		
			$selectedBMArray->outputDialog('Close Window','javascript:self.close()');
			
		}
		
	} else { 
	
		$r->outputDialog('Close Window','javascript:self.close()');
			
	}
	
} else {
	
	Error::outputDialog('Close Window','javascript:self.close()', 'Only an administrator may specify this information.');

}

include('layout/footer_popup.php'); ?>
